﻿#region Imports
using System;
using System.Globalization;
using System.Windows.Data;
using CommonUtilities.Models;
#endregion Imports

namespace PlayRandom.Converters
{
    public class FileSizeConverter : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            long size = 0;
            if (Int64.TryParse(System.Convert.ToString(value), out size))
                return new MemoryMgmt(CommonUtilities.Enums.eByteValueType.B, size).PracticalSize;

            throw new InvalidOperationException("Invalid size in Bytes");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        #endregion IValueConverter Members
    }
}
